package uilayer;

import java.util.InputMismatchException;
import java.util.Scanner;

/**
 * The Class MainMenuUI.
 *@author Benjamin Ørskov
 *@author Lasse Lambertsen
 *@author Ole Kirk
 *@author Søren Søgaard
 */
public class MainMenuUI {

	/** The ItemUI UI. */
	private ItemUI iUI;

	/** The p ui. */
	private PersonUI pUI;

	/** The o ui. */
	private OrderUI oUI;

	/** The t ui. */
	private TrackingUI tUI;

	/**
	 * The main method.
	 *
	 * @param args
	 *            the arguments
	 */
	public static void main(String[] args) {
		MainMenuUI mainMenuUI;
		mainMenuUI = new MainMenuUI();
		mainMenuUI.mainMenu();
	}

	/**
	 * Instantiates a new main menu ui.
	 */
	private MainMenuUI() {
		iUI = ItemUI.getInstance();
		pUI = PersonUI.getInstance();
		oUI = OrderUI.getInstance();
		tUI = TrackingUI.getInstance();
	}

	/**
	 * Write main menu.
	 *
	 * @return the int
	 */
	private int writeMainMenu() {
		Scanner keyboard = new Scanner(System.in);
		System.out.println("*** Hovedmenu ***");
		System.out.println(" (1) Ordre");
		System.out.println(" (2) Varer");
		System.out.println(" (3) Person");
		System.out.println(" (4) Tracking");
		System.out.println(" (5) Afslut");
		System.out.print("\n Vælg: ");
		int choice = keyboard.nextInt();
		return choice;
	}

	/**
	 * Main menu.
	 */
	private void mainMenu() {
		boolean exit = false;
		try {
			while (!exit)// that is: while exit is false
			{
				int choice = writeMainMenu();
				if (choice == 1) { // Order Menu
					oUI.orderMenu();
				} else if (choice == 2) { // Item Menu
					iUI.itemMenu();
				} else if (choice == 3) {
					// Person menu
					pUI.personMenu();
				} else if (choice == 4) {
					// Person menu
					tUI.trackingMenu();
				} else {
					exit = true;
				}// end else

			}// end while
		}// end try
		catch (InputMismatchException e) {
			// Prints appropriate error message
			System.out.println("Du skal indtaste et tal!");
			mainMenu();
		}
	}
}
